﻿/*
// Draslið hennar ingu dísar:

// Einhver despó tilraun til þess að finna út "winning combinations" í myllu... idk
var comb1 = cell1.innerText == cell2.innerText == cell3.innerText == 'X';
var comb2 = cell4.innerText == cell5.innerText == cell6.innerText == 'X';
var comb3 = cell7.innerText == cell8.innerText == cell9.innerText == 'X';
var comb4 = cell1.innerText == cell4.innerText == cell7.innerText == 'X';
var comb6 = cell2.innerText == cell5.innerText == cell8.innerText == 'X';
var comb7 = cell3.innerText == cell6.innerText == cell9.innerText == 'X';
var comb8 = cell1.innerText == cell5.innerText == cell9.innerText == 'X';
var comb9 = cell3.innerText == cell5.innerText == cell7.innerText == 'X';


// Ég vil svona!
var player1 = '@(Model.PlayerXId)';
var player2 = '@(Model.PlayerOId)';

// Hurkaderp
$(function () {
    if ((comb1 || comb2 || comb3 || comb4 || comb5 || comb6 || comb7 || comb8 || comb9) == 'X') {
        // Hérna vil ég vita HVER SETTI X OG HVER SETTI O, og fokkings gefa honum stig..
        // Ef eg myndi gera þetta svona, þá væri önnur if setning fyrir 'O' r sum
    }
});


// Frá DABS:
*/

var player1 = ""
var player2 = ""


$(function () {
    var currentPlayer = 0;

    var group = '@(Model.GameId)';
    var hub = $.connection.tTTGameHub;

    hub.client.cellClicked = function (cellId) {
        if (currentPlayer % 2 === 1) {
            $("#" + cellId).text("O");
            ++currentPlayer;
        }
    };

    $.connection.hub.start().done(function () {
        hub.server.join(group);

        $("#tictactoe tr td").click(function () {
            if (currentPlayer % 2 === 0) {
                hub.server.clickCell(group, this.id);
                $(this).text("X");
                ++currentPlayer
            }
        });
    });
});
